package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizActivityGoods;
import com.member.shop.domain.SysBizActivityUser;
import com.member.shop.service.ISysBizActivityGoodsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【参与活动商品】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2024-11-09
 **/
@RestController
@RequestMapping("/shop/activityGoods")
public class SysBizActivityGoodsController extends BaseController {
    @Resource
    private ISysBizActivityGoodsService sysBizActivityGoodsService;

    private void setTenantId(SysBizActivityGoods sysBizActivityGoods) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizActivityGoods.setTenantId(tenantId);
        }
    }

    /**
     * 查询参与活动商品列表
     */
    @PreAuthorize("@ss.hasPermi('shop:activityGoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizActivityGoods sysBizActivityGoods) {
        startPage();
        setTenantId(sysBizActivityGoods);
        List<SysBizActivityGoods> list = sysBizActivityGoodsService.selectSysBizActivityGoodsList(sysBizActivityGoods);
        return getDataTable(list);
    }

    /**
     * 导出参与活动商品列表
     */
    @PreAuthorize("@ss.hasPermi('shop:activityGoods:export')")
    @Log(title = "参与活动商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizActivityGoods sysBizActivityGoods) {
        setTenantId(sysBizActivityGoods);
        List<SysBizActivityGoods> list = sysBizActivityGoodsService.selectSysBizActivityGoodsList(sysBizActivityGoods);
        ExcelUtil<SysBizActivityGoods> util = new ExcelUtil<SysBizActivityGoods>(SysBizActivityGoods.class);
        util.exportExcel(response, list, "参与活动商品数据");
    }

    /**
     * 获取参与活动商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:activityGoods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizActivityGoodsService.selectSysBizActivityGoodsById(id));
    }

    /**
     * 新增参与活动商品
     */
    @PreAuthorize("@ss.hasPermi('shop:activityGoods:add')")
    @Log(title = "参与活动商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizActivityGoods sysBizActivityGoods) {
        return toAjax(sysBizActivityGoodsService.insertSysBizActivityGoods(sysBizActivityGoods));
    }

    /**
     * 修改参与活动商品
     */
    @PreAuthorize("@ss.hasPermi('shop:activityGoods:edit')")
    @Log(title = "参与活动商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizActivityGoods sysBizActivityGoods) {
        return toAjax(sysBizActivityGoodsService.updateSysBizActivityGoods(sysBizActivityGoods));
    }

    /**
     * 删除参与活动商品
     */
    @PreAuthorize("@ss.hasPermi('shop:activityGoods:remove')")
    @Log(title = "参与活动商品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizActivityGoodsService.deleteSysBizActivityGoodsByIds(ids));
    }
}
